<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
    <style>
        div {
            width: 120px;
            height: 100px;
            background-color: red;
        }

        .copy {
            width: 200px;
            height: 200px;
            background-color: rosybrown;
        }
    </style>
</head>
<body>
    <div></div>
    <div class="copy"></div>

    <script>
        // 获取div标签
        var div = document.querySelector("div");
        var copy = document.querySelector(".copy");
        // 调用获取元素样式对象的方法
        // 调用者： window
        // 参数： dom对象
        // 返回值： css样式对象
        // 功能： 可以获取元素的css属性数据
        var obj = getComputedStyle(div);
        var rbq = getComputedStyle(copy);

        // 取值
        console.log(obj.width);
        console.log(obj.height);
        console.log(obj.backgroundColor);

        console.log(rbq.width);
        console.log(rbq.height);
        console.log(rbq.backgroundColor);

        // 取值
        var w = getComputedStyle(div)["width"];
        console.log(w);// "100px"
        console.log(parseInt(w));// 100

        var h = getComputedStyle(copy)["height"];
        console.log(h);
        console.log(parseInt(h));

        

    </script>
</body>
</html>